package com.zhongshengnetwork.rightbe.lang.activity;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
//import android.support.annotation.Nullable;
//import android.support.v4.app.Fragment;
//import android.support.v4.app.FragmentActivity;
//import android.support.v4.app.FragmentManager;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;

import com.gyf.barlibrary.BarHide;
import com.gyf.barlibrary.ImmersionBar;
import com.zhongshengnetwork.rightbe.Adv.activity.SplashActivity;
import com.zhongshengnetwork.rightbe.MainActivity;
import com.zhongshengnetwork.rightbe.R;
import com.zhongshengnetwork.rightbe.common.AppThemeUtils;
import com.zhongshengnetwork.rightbe.common.AppUtils;
import com.zhongshengnetwork.rightbe.common.StatusBarFontUtil;

import java.util.List;

//import cn.jiguang.analytics.android.api.JAnalyticsInterface;

/**
 * Created by luojingxing on 2018/6/18.
 */

public class BaseFragmentActivity extends FragmentActivity {
    private String TAG="BaseFragmentActivity";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (AppUtils.getInstance().getAppStatus() == AppUtils.STATUS_FORCE_KILLED){
            //app被系统回收了，重新启动应用
            protectApp();
        }
        // 所有子类都将继承这些相同的属性,请在设置界面之后设置
        ImmersionBar.with(this)
                .statusBarColor(AppThemeUtils.getInstance().getThemeColorString())
                .navigationBarColor(AppThemeUtils.getInstance().getMainColorString()) //设置导航栏（虚拟键盘的颜色）
                .hideBar(BarHide.FLAG_SHOW_BAR)
                //.fitsSystemWindows(true)  //使用该属性必须指定状态栏的颜色，不然状态栏透明，很难看
                .init();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // 如果你的app可以横竖屏切换，并且适配4.4或者emui3手机请务必在onConfigurationChanged方法里添加这句话
        ImmersionBar.with(this)
                .statusBarColor(AppThemeUtils.getInstance().getThemeColorString())
                .navigationBarColor(AppThemeUtils.getInstance().getMainColorString()) //设置导航栏（虚拟键盘的颜色）
                //.fitsSystemWindows(true)  //使用该属性必须指定状态栏的颜色，不然状态栏透明，很难看
                .init();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if(AppUtils.getInstance().isUserAgreeStatus() == false){
    return;
}
//JAnalyticsInterface.onPageStart(getApplicationContext(),this.getClass().getCanonicalName());
    }


    @Override
    protected void onPause() {
        super.onPause();
        if(AppUtils.getInstance().isUserAgreeStatus() == false){
    return;
}
//JAnalyticsInterface.onPageEnd(getApplicationContext(),this.getClass().getCanonicalName());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 必须调用该方法，防止内存泄漏
        ImmersionBar.with(this).destroy();
    }

    protected void protectApp() {
//        Intent intent = new Intent(this, MainActivity.class);
//        intent.putExtra(AppUtils.KEY_HOME_ACTION, AppUtils.ACTION_RESTART_APP);
//        startActivity(intent);

        Intent intent = new Intent(this, SplashActivity.class);
        startActivity(intent);
        System.exit(0);
        finish();

//        final Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
//        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//        startActivity(intent);

        //杀掉以前进程
        //android.os.Process.killProcess(android.os.Process.myPid());
    }

}
